import type { GlobEnvConfig } from '/#/global';
import pkg from '../../package.json'

import { getConfigFileName } from '../../build/getConfigFileName';



export function getEnv(): string {
    return import.meta.env.MODE;
}

export function getCommonStoragePrefix(){
    const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
    return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase();
}

export function getAppEnvConfig(){
    const ENV_NAME = getConfigFileName(import.meta.env);

    const ENV = (import.meta.env.DEV 
        ? (import.meta.env as unknown as GlobEnvConfig) 
        : window[ENV_NAME as any]) as unknown as GlobEnvConfig;

    const {
    VITE_GLOB_APP_TITLE,
    VITE_GLOB_API_URL,
    VITE_USE_MOCK,
    VITE_GLOB_APP_SHORT_NAME,
    VITE_GLOB_API_URL_PREFIX,
    VITE_GLOB_APP_OPEN_SSO,
    VITE_GLOB_APP_OPEN_QIANKUN,
    VITE_GLOB_APP_CAS_BASE_URL,
    VITE_GLOB_DOMAIN_URL,
    VITE_GLOB_ONLINE_VIEW_URL,
} = ENV;

return {
    VITE_GLOB_APP_TITLE,
    VITE_GLOB_API_URL,
    VITE_USE_MOCK,
    VITE_GLOB_APP_SHORT_NAME,
    VITE_GLOB_API_URL_PREFIX,
    VITE_GLOB_APP_OPEN_SSO,
    VITE_GLOB_APP_OPEN_QIANKUN,
    VITE_GLOB_APP_CAS_BASE_URL,
    VITE_GLOB_DOMAIN_URL,
    VITE_GLOB_ONLINE_VIEW_URL,};
}




export function isDevMode(): boolean {
    return import.meta.env.DEV;
}


export function getStorageShortName(){
    return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase();
}